package com.example.dormitory.service;


import com.example.dormitory.entity.*;
import com.example.dormitory.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class ClassDormitoryService {

    @Autowired
    private ClassDormitoryMapper classDormitoryMapper;

    public int create(ClassDormitory classDormitory) {
        return classDormitoryMapper.create(classDormitory);
    }

    public int delete(String ids) {
        String[] arr = ids.split(",");
        int row = 0;
        for (String s : arr) {
            if(!StringUtils.isEmpty(s)){
                classDormitoryMapper.delete(Integer.parseInt(s));
            row++;
            }
        }
        return row;
    }

    public int delete(Integer id) {
        return classDormitoryMapper.delete(id);
    }

    public int update(ClassDormitory classDormitory) {
        return classDormitoryMapper.update(classDormitory);
    }

    public int updateSelective(ClassDormitory classDormitory) {
        return classDormitoryMapper.updateSelective(classDormitory);
    }

    public PageInfo<ClassDormitory> query(ClassDormitory classDormitory) {
        if(classDormitory != null && classDormitory.getPage() != null){
            PageHelper.startPage(classDormitory.getPage(),classDormitory.getLimit());
        }
        return new PageInfo<ClassDormitory>(classDormitoryMapper.query(classDormitory));
    }

    public ClassDormitory detail(Integer id) {
        return classDormitoryMapper.detail(id);
    }

    public int count(ClassDormitory classDormitory) {
        return classDormitoryMapper.count(classDormitory);
    }
}
